---
description: "Reference for Nitric's v0 Go library - Returns a reference to a known version of a secret."
---

# Go - Secret.Version()

Returns a reference to a known version of a secret.

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  version := secret.Version("the-version-id")

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="version" required type="string">
    The version ID. This value is returned from [secret.Put()](./secret-put).
  </Property>
</Properties>

## Examples

### Return a reference to a known secret version

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  version := secret.Version("the-version-id")

  nitric.Run()
}
```

### Access the value of a known secret version

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  version, err := secret.Version("the-version-id").Access(context.TODO())
  if err != nil {
    fmt.Println(err)
    return
  }

  fmt.Println(version.AsString())

  nitric.Run()
}
```

### See also

- [Secret.Version().Access()](./secret-version-access)
